import { HttpStatus } from "@nestjs/common";
import { ApiBadRequestResponse, ApiRequestTimeoutResponse } from "@nestjs/swagger";
import { CrudOptions } from "@nestjsx/crud";
import { HandleStatus } from "libs/db/entity/enum/handle-status.enum";
import { Logger } from "libs/db/entity/logger.entity";
import { LoggerInfo, moduleLoggerInfo } from "../_decorator/logger-info";

export const LoggerCrudOps: CrudOptions = {
  model: {
    type: Logger
  },
  query: {
    join: {
      user: {
        exclude:  ["updatedAt", "deleteAt", "password"],
      },
      "user.area": {
        exclude:  ["updatedAt", "deleteAt"],
      },
      "user.village": {
        exclude:  ["updatedAt", "deleteAt"],
      },
      "user.town": {
        exclude:  ["updatedAt", "deleteAt"],
      },
    },
  },
  routes: {
    only: ['getManyBase', 'deleteOneBase'],
    getManyBase: {
      interceptors: [],
      decorators: [
        ApiBadRequestResponse({
          description: '参考相关 DTO 参数说明',
          status: HttpStatus.BAD_REQUEST,
          // schema: BadRequestException
          // schema: HttpErrorByCode(HttpStatus.BADLoggerREQUEST)
        }),
        ApiRequestTimeoutResponse({
          description: '请求超时',
          status: HttpStatus.REQUEST_TIMEOUT,
        }),
        LoggerInfo(
          new moduleLoggerInfo ('日志查询', HandleStatus.LOG)
        ),
      ],
    },
    deleteOneBase: {
      interceptors: [],
      decorators: [
        // LoggerInfo(
        //   new moduleLoggerInfo ('删除日志信息', HandleStatus.LOG)
        // ),
      ],
      returnDeleted: true,
    },
  },
  serialize: {
    getMany: Logger,
    delete: Logger
  }
}